/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2005, 2008. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:  Use,
 * duplication or disclosure restricted by GSA ADP Schedule
 * Contract with IBM Corp.
 *******************************************************************************/

package org.eclipsecon.dui.interpreter.internal;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.part.ViewPart;
import org.eclipsecon.dui.interpreter.internal.ModelContainer.Target;

public class ModelView extends ViewPart {
	private ModelContainer fContainer;

	private ModelContext context= new ModelContext();

	/*
	 * @see
	 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
	 * .Composite)
	 */
	@Override
	public void createPartControl(final Composite parent) {
		fContainer= new ModelContainer(context);
		fContainer.create(parent);

		IViewSite viewSite= (IViewSite) getSite();
		IToolBarManager toolBarManager= viewSite.getActionBars().getToolBarManager();
		toolBarManager.add(new LoadAction(fContainer, getSite().getShell()));
		toolBarManager.add(new BindAction(fContainer, context, getSite().getShell()));
		toolBarManager.add(new Separator());
		toolBarManager.add(new ReloadAction(fContainer));
		toolBarManager.add(new Separator());

		Action action= new Action("SWT", IAction.AS_RADIO_BUTTON) {
			@Override
			public void run() {
				fContainer.setTarget(Target.SWT);

				if (fContainer.getModelPath() != null)
					new ReloadJob(fContainer, fContainer.getModelPath(), fContainer.getScript()).schedule();
			}
		};
		action.setChecked(true);
		toolBarManager.add(action);

		toolBarManager.add(new Action("HTML", IAction.AS_RADIO_BUTTON) {
			@Override
			public void run() {
				fContainer.setTarget(Target.HTML);

				if (fContainer.getModelPath() != null)
					new ReloadJob(fContainer, fContainer.getModelPath(), fContainer.getScript()).schedule();
			}
		});
	}

	/*
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
	 */
	@Override
	public void setFocus() {}
}